package org.schat.sockets.handlers;

import java.util.Set;

import org.schat.sockets.ChatMessage;
import org.schat.sockets.ChatSocket;

public class JoinHandler implements IMessageHandler {

	@Override
	public void handle(ChatSocket socket, ChatMessage message) {
		socket.init(message.getRoom(), message.getName(), message.getAvatarClass(), System.currentTimeMillis());
		Set<ChatSocket> room = socket.getRoom();
		socket.send(message.setJoinTime(System.currentTimeMillis()));
		room.add(socket);
		ChatSocket.sendUsers(socket);
	}

}
